#include "playslider.h"
#include "ui_playslider.h"

playSlider::playSlider(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::playSlider)
{
    playGrogress = 0;
    ui->setupUi(this);
    moveSlider();
}

playSlider::~playSlider()
{
    delete ui;
}

void playSlider::mousePressEvent(QMouseEvent *event)
{
    if(event->button() == Qt::LeftButton)
    {
        playGrogress = event->pos().x();
        moveSlider();
        return;
    }
    QWidget::mousePressEvent(event);
}

void playSlider::mouseMoveEvent(QMouseEvent *event)
{
    QRect playSliderRect = QRect(0,0,this->width(),this->height());
    if(!playSliderRect.contains(event->pos()))
    {
        LOG()<<"非目标事件";
        return;
    }

    if(event->buttons() == Qt::LeftButton)
    {
        if(playGrogress<0)
        {
            playGrogress = 0;
        }

        int maxwidth = this->width();
        if(event->pos().x()>maxwidth)
        {
            playGrogress = maxwidth;
        }
        moveSlider();
        return;
    }
    QWidget::mouseMoveEvent(event);
}

void playSlider::mouseReleaseEvent(QMouseEvent *event)
{
    if(event->buttons() == Qt::LeftButton)
    {
        playGrogress = event->pos().x();
        //在这里描述加载对应视频加载逻辑
        moveSlider();
        return ;
    }
    QWidget::mouseReleaseEvent(event);
}

void playSlider::moveSlider()
{
    ui->outLine->setGeometry(ui->outLine->x(),ui->outLine->y(),playGrogress,ui->outLine->height());
}
